package priv.pront.code.national.acwing.dp.linear.trangle;

import java.util.Scanner;

public class Acwing1207_方格取数 {

    static int[][] arr;
    static int[][][] f;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        arr = new int[n + 1][n + 1];
        f = new int[2 * n + 1][n + 1][n + 1];
        while (true) {
            int o1 = sc.nextInt();
            int o2 = sc.nextInt();
            int o3 = sc.nextInt();
            if (o1 == 0 || o2 == 0) break;
            arr[o1][o2] = o3;
        }

        for (int k = 2; k <= 2 * n; k++) {
            for (int i1 = 1; i1 <= n; i1++) {
                for (int i2 = 1; i2 <= n; i2++) {
                    int j1 = k - i1;
                    int j2 = k - i2;
                    if (j1 >= 1 && j2 >= 1 && j1 <= n && j2 <= n) {//保证坐标的合法
                        f[k][i1][i2] = Math.max(f[k - 1][i1 - 1][i2 - 1], Math.max(f[k - 1][i1][i2 - 1], Math.max(f[k - 1][i1][i2], f[k - 1][i1 - 1][i2])));
                        if (i1 != i2) f[k][i1][i2] += arr[i1][k - i1];
                        f[k][i1][i2] += arr[i2][k - i2];
                    }
                }
            }
        }
        System.out.println(f[2 * n][n][n]);
    }
}
